<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购计划商品列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                采购计划：<select id="purchasePlanId" name="purchasePlanId" class="form-control">
                                <option th:each="purchasePlan : ${purchasePlans}" th:text="${purchasePlan['title']}" th:value="${purchasePlan['purchasePlanId']}" th:field="*{purchasePlan.purchasePlanId}"></option>
                            </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="system:purchaseitem:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:purchaseitem:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:purchaseitem:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:purchaseitem:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-danger" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:purchaseitem:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:purchaseitem:remove')}]];
        var resetJingjiaFlag = [[${@permission.hasPermi('system:purchaseitem:resetJingjia')}]];
        var prefix = ctx + "system/purchaseitem";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                queryParams: queryParams,
                modalName: "采购计划商品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'purchaseItemId',
                    title: '采购商品表ID',
                    visible: false
                },
                    {
                        field: 'attribute3',
                        title: '货物分类'
                    },
                {
                    field: 'attribute2',
                    title: '采购计划'
                },
                {
                    field: 'attribute1',
                    title: '货物名称'
                },
                    {
                        field: 'bidStatus',
                        title: '审核状态',
                        formatter: function(value, row, index) {
                            // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                            // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                            if(value=='0'){
                                return "竞价成功"
                            }else if(value=='1'){
                                return '竞价中'
                            }else if(value=='-1'){
                                return "竞价失败";
                            }else{
                                return "未开启竞价";
                            }



                        }
                    },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.bidStatus!='1'&&row.bidStatus!='0'){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.purchaseItemId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.purchaseItemId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        if(row.bidStatus==''||row.bidStatus==null||row.bidStatus==undefined){
                            actions.push("<a class='btn btn-default btn-xs " + resetJingjiaFlag + "' href='javascript:void(0)' onclick='jingjia(" + row.purchaseItemId + ")'><i class='fa fa-key'></i>开启竞价</a> ");
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.purchasePlanId = $("#purchasePlanId").val();
            return search;
        }

        /*字典数据-新增字典*/
        function add() {
            var purchasePlanId = $("#purchasePlanId option:selected").val();
            $.operate.add(purchasePlanId);
        }

        function resetPre() {
            $.form.reset();
            $("#purchasePlanId").val($("#purchasePlanId").val()).trigger("change");
        }
        /* 开启竞价 */
        function jingjia(purchaseItemId) {
            var url = prefix + '/resetJingjia/' + purchaseItemId;
            $.modal.open("开启竞价", url, '800', '600');
        }
    </script>
</body>
</html>